#define DEBUG
#include <cstdio>
#define MAXLEN 30000
#define MAXK 15

using namespace std;

int max(int a, int b) {
  return a>b ? a : b;
}

int main() {
#ifdef DEBUG
  freopen("4669.in", "r", stdin);
  freopen("4669.out", "w", stdout);
#endif

  static char s[MAXLEN+2];
  static int p[MAXLEN+1], f[MAXLEN+1][MAXK+1], dep[MAXLEN+1];
  scanf("%s", s+1);
  for (int i=2; s[i]!='\0'; i++) {
    int x=p[i-1];
    for (; x && s[i]!=s[x+1]; x=p[x]);
    if (s[i]==s[x+1]) {
      p[i]=x+1;
    } else {
      p[i]=0;
    }
    f[i][0]=p[i];
  }
  dep[0]=0;
  for (int i=1; s[i]!='\0'; i++) {
    dep[i]=dep[p[i]]+1;
  }
  for (int i=1; i<=MAXK; i++) {
    for (int j=1; s[j]!='\0'; j++) {
      f[j][i]=f[f[j][i-1]][i-1];
    }
  }

  int m;
  scanf("%d", &m);
  for (int i=1; i<=m; i++) {
    int l, r, a, b;
    scanf("%d %d", &l, &r);
    if (dep[l]>dep[r]) {
      a=l, l=r, r=a;
    }
    a=b=0;
    for (int j=MAXK; j>=0; j--) {
      if (dep[f[r][j]]>=dep[l]) {
	r=f[r][j];
      }
    }
    if (l!=r) {
      for (int j=MAXK; j>=0; j--) {
	if (f[l][j]!=f[r][j]) {
	  l = f[l][j], r = f[r][j];
	}
      }
      l = f[l][0];
    }
    printf("%d %d\n", dep[l], l);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
